package com.yztc.love_travel.ui;



import com.yztc.love_travel.bean.BuyingBean;
import com.yztc.love_travel.bean.EatingBean;
import com.yztc.love_travel.bean.HotelBean;

import java.util.Map;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * Created by 周旭 on 2016/11/28.
 */

public class HttpUtils {

    private static Retrofit retrofit;
    private static RetrofitInterface retrofitInterface;

    private static void initRetrofit(String baseUrl){
        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        retrofitInterface =  retrofit.create(RetrofitInterface.class);
    }

    public static Observable<EatingBean> getEatingBean(String baseUrl, Map<String,Object> params){
        initRetrofit(baseUrl);
        return retrofitInterface.getEatingBean(params);
    }

    public static Observable<HotelBean> getHotelBean(String baseUrl, Map<String,Object> params){
        initRetrofit(baseUrl);
        return retrofitInterface.getHotelBean(params);
    }

    public static Observable<BuyingBean> getBuyingBean(String baseUrl, Map<String,Object> params){
        initRetrofit(baseUrl);
        return retrofitInterface.getBuyingBean(params);
    }
}
